package candy;

import java.io.Serializable;

public class MilkCandy extends Sweet implements Serializable{
	protected double rateOfMilk;
	
	public MilkCandy(int id, String name, double albumens, double fats,
			double carbohydrates, double weight, double price, double rateOfMilk) {
		super(id, name, albumens, fats, carbohydrates, weight, price);
		this.rateOfMilk = rateOfMilk;
	}

	@Override
	protected double calculateCalorificValue() {
		return 4.35*(this.getAlbumens()+this.getCarbohydrates()+this.getFats());	
	}
	public double getRateOfMilk() {
		return rateOfMilk;
	}

	public void setRateOfMilk(double rateOfMilk) {
		this.rateOfMilk = rateOfMilk;
	}

	@Override
	public String toString() {		
		String str = "";
		str= "MilkCandy #" + this.id + "  " + this.name + "\n" 
			  +	"albumens = " + this.albumens + " carbohydrates = " + this.carbohydrates
			  + "\n" +  "fats = " + this.fats + " rate of milk = " + this.rateOfMilk
			  + "\n" +  "weight = " + this.weight + " price = " + this.price
			  +  "\n" + "calorific value = " + this.calculateCalorificValue() + "\n" 
			  + "-------------";
		return str;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		long temp;
		temp = Double.doubleToLongBits(rateOfMilk);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (!(obj instanceof MilkCandy)) {
			return false;
		}
		MilkCandy other = (MilkCandy) obj;
		if (Double.doubleToLongBits(rateOfMilk) != Double
				.doubleToLongBits(other.rateOfMilk)) {
			return false;
		}
		return true;
	}
}
